<?php

namespace app\modules\setting\controllers\seller;

use Yii;
use app\modules\setting\models\seller\EtcSellerTiktokShop;
use app\modules\setting\configs\seller\YgldpConfig;
use app\modules\setting\models\seller\EtcSellerTiktokShopSearch;
use sookie\react\AdminController;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use yii\base\Exception;
use sookie\excel\SaveExcel;
use sookie\db\DBHandler;
use sookie\react\handlers\ImportHandler;


/**
 * YgldpController implements the CRUD actions for EtcSellerTiktokShop model.
 */
class YgldpController extends AdminController
{
    /**
    * @return array
    * 列表数据
    */
    public function actionIndex()
    {
        try {
            $searchModel = new EtcSellerTiktokShopSearch();
            $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
            $data = $dataProvider->getModels();
            if($data){
                $data = array_map(function($item){
                    $item['shop_icon'] = "<img src='{$item['shop_icon']}' height=100 />";
                    return $item;
                },$data);
            }
            return ArrayHelper::merge(["data" => $data, "pagination" => $dataProvider->getPagination()],YgldpConfig::configIndex());
        }catch (\Throwable $e){
            return ["ok" => false,"msg" => $e->getMessage(),"code" => 401];
        }
    }






    protected function findModel($id)
    {
        if (($model = EtcSellerTiktokShop::findOne($id)) !== null) {
            return $model;
        }

        throw new Exception('不存在的记录');
    }




}

